package com.ischoolbar.programmer.dao;
/**
 * @Author lin
 **/

import com.ischoolbar.programmer.model.Admin;

import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDao extends BaseDao {
    public AdminDao() {
    }

    public Admin login(String name, String password) {
        String sql = "select * from s_admin where name = '" + name + "' and password = '" + password + "'";
        ResultSet resultSet = this.query(sql);

        try {
            if (resultSet.next()) {
                Admin admin = new Admin();
                admin.setId(resultSet.getInt("id"));
                admin.setName(resultSet.getString("name"));
                admin.setPassword(resultSet.getString("password"));
                admin.setStatus(resultSet.getInt("status"));
                return admin;
            }
        } catch (SQLException var6) {
            var6.printStackTrace();
        }
        return null;
    }

    public boolean editPassword(Admin admin, String newPassword) {
        String sql = "update s_admin set password = '" + newPassword + "' where id = " + admin.getId();
        return this.update(sql);
    }
}

